package com.woniu.liuzhougov.common.config;

import com.alibaba.druid.support.http.StatViewServlet;
import com.woniu.liuzhougov.businessproject.utils.BusinessProjectInitMVC;

import com.woniu.liuzhougov.relatedinformation.utils.RelatedInformationInitMVC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Value("${upload.path}")
    private String upload;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println(upload);
        registry.addResourceHandler("/upload/**").addResourceLocations(upload);
    }

    //注册一个视图控制器
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("main");
        registry.addViewController("/new.html").setViewName("new");
        registry.addViewController("/MyNotice.html").setViewName("MyNotice");
        registry.addViewController("/DistrictLevelSupervisionMatters.html").setViewName("DistrictLevelSupervisionMatters");
        registry.addViewController("/itemStatistics.html").setViewName("itemStatistics");
        registry.addViewController("/MunicipalAffairsManagement.html").setViewName("MunicipalAffairsManagement");
        registry.addViewController("/AwaitingApprovalReport.html").setViewName("AwaitingApprovalReport");
        registry.addViewController("/MyItemReport.html").setViewName("MyItemReport");
        registry.addViewController("/MyItems.html").setViewName("MyItems");
        registry.addViewController("/AwaitingApprovalItems.html").setViewName("AwaitingApprovalItems");


        registry.addViewController("register.html").setViewName("register");



        registry.addViewController("file_item.html").setViewName("file_item");



		//配置招商管理模块页面
        BusinessProjectInitMVC.initMVC(registry);
        //配置相关信息模块
        RelatedInformationInitMVC.initMVC(registry);

        registry.addViewController("/good_enterprise _index.html").setViewName("good_enterprise _index");

        registry.addViewController("/districtquery.html").setViewName("districtquery");
        registry.addViewController("/cityquery.html").setViewName("cityquery");
        registry.addViewController("/centerquery.html").setViewName("centerquery");
        registry.addViewController("/keyquery.html").setViewName("keyquery");

        //文件管理
        registry.addViewController("file_manage_index.html").setViewName("file_manage_index");
        registry.addViewController("file_manage_upload.html").setViewName("file_manage_upload");
        registry.addViewController("file_manage_update.html").setViewName("file_manage_update");
        registry.addViewController("/file_manage_upload_business_project.html").setViewName("file_manage_upload_business_project");


        //子任务
        registry.addViewController("item_task_index.html").setViewName("item_task_index");
        registry.addViewController("item_task_index_add.html").setViewName("item_task_index_add");
        registry.addViewController("item_task_index_detile.html").setViewName("item_task_index_detile");
        registry.addViewController("item_task_index_update.html").setViewName("item_task_index_update");
        registry.addViewController("my_item_task.html").setViewName("my_item_task");
        registry.addViewController("item_task_my.html").setViewName("item_task_my");
        registry.addViewController("item_task_index_detile_given.html").setViewName("item_task_index_detile_given");

        //督办单
        registry.addViewController("supervision_my.html").setViewName("supervision_my");
        registry.addViewController("supervision_given.html").setViewName("supervision_given");



        registry.addViewController("/noticeManager.html").setViewName("noticeManager");
        registry.addViewController("item_task_index.html").setViewName("item_task_index");
        registry.addViewController("/personalNotice.html").setViewName("personalNotice");


        //系统设置和日志
        registry.addViewController("/item_type_index.html").setViewName("item_type_index");
        registry.addViewController("/tb_check_status_index.html").setViewName("tb_check_status_index");
        registry.addViewController("/log.html").setViewName("log");

        registry.addViewController("/area.html").setViewName("area");

        //系统设置和日志
        registry.addViewController("/item_type_index.html").setViewName("item_type_index");
        registry.addViewController("/tb_check_status_index.html").setViewName("tb_check_status_index");
        registry.addViewController("/log.html").setViewName("log");


        /**
         * 工作计划
         */
        //部门工作计划列表
        registry.addViewController("/work_plan.html").setViewName("work_plan");
        //部门工作计划添加页面
        registry.addViewController("/work_plan_add.html").setViewName("work_plan_add");
        //部门工作计划详情展示页面
        registry.addViewController("/work_plan_detail.html").setViewName("work_plan_detail");
        //当前登陆用户部门已发布的工作计划展示列表
        registry.addViewController("/work_plan_department.html").setViewName("work_plan_department");
        //当前登陆用户工作计划详情页面
        registry.addViewController("/work_plan_department_detail.html").setViewName("work_plan_department_detail");
    }

    //   配置数据源
    @Bean
    public DataSourceTransactionManager manager(DataSource dataSource) {
        DataSourceTransactionManager manager = new DataSourceTransactionManager();
        manager.setDataSource(dataSource);
        return manager;
    }

    //配置druid的负责展示视图的页面和请求
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        StatViewServlet statViewServlet = new StatViewServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
        servletRegistrationBean.addUrlMappings("/druid/*");
        Map init = new HashMap();
        init.put("allow", "127.0.0.1");
        servletRegistrationBean.setInitParameters(init);
        servletRegistrationBean.setServlet(statViewServlet);
        return servletRegistrationBean;
    }

}


